// src/api/family.ts
import request from './request';
import type { FamilyTree, CreateFamilyTreeRequest, Person } from '@/types/api';

/**
 * 获取当前用户的所有家谱
 */
export const getFamilyTreeListApi = (): Promise<FamilyTree[]> => {
    return request({ url: '/api/family-trees', method: 'get' });
};

/**
 * 创建新家谱
 * @param data 家谱信息
 */
export const createFamilyTreeApi = (data: CreateFamilyTreeRequest): Promise<FamilyTree> => {
    return request({ url: '/api/family-trees', method: 'post', data });
};

/**
 * 更新家谱信息
 * @param id 家谱ID
 * @param data 家谱信息
 */
export const updateFamilyTreeApi = (id: number, data: CreateFamilyTreeRequest): Promise<FamilyTree> => {
    return request({ url: `/api/family-trees/${id}`, method: 'put', data });
};

/**
 * 删除家谱
 * @param id 家谱ID
 */
export const deleteFamilyTreeApi = (id: number): Promise<void> => {
    return request({ url: `/api/family-trees/${id}`, method: 'delete' });
};

/**
 * 【新增】根据家谱ID获取其所有成员
 * @param treeId 家谱ID
 */
export const getPersonsByFamilyTreeIdApi = (treeId: number): Promise<Person[]> => {
    return request({ url: `/api/family-trees/${treeId}/persons`, method: 'get' });
};
